# -*- coding: UTF-8 -*-

__author__ = 'anan'

import werobot
import cache
import utils

cache = cache.Cache()
robot = werobot.WeRoBot(token='zhangzhongnan')

@robot.subscribe
def first_watch(message):
    return u'你好啊亲爱的朋友\n这里是测试微信公众平台，输入help获取帮助'


@robot.text
def handle_text(message):
    status = cache.get_status(message.source)
    tag = cache.get_tag(message.source)

    if tag == 'jump_to_EXAM_DAY_ensure':
        if message.content == 'Y':
            cache.set_status(message.source, 'EXAM_DAY')
    if tag == 'jump_to_EXAM_WEEK_ensure':
        if message.content == 'Y':
            cache.set_status(message.source, 'EXAM_WEEK')
    if tag == 'jump_to_EXAM_REAL_ensure':
        if message.content == 'Y':
            cache.set_status(message.source, 'EXAM_REAL')

    return u'点击对应的按钮完成相应功能，输入help查看帮助'


@robot.key_click('EXAM_REAL')
def handler_bt_exam_day(message):
    return u'你点击了考试菜单'


@robot.key_click('EXAM_WEEK')
def handler_bt_exam_day(message):
    return u'你点击了每周评测菜单'


@robot.key_click('EXAM_DAY')
def handler_bt_exam_day(message):
    status = cache.get_status(message.sources)
    if status == 'EXAM_DAY':
        return u'您这不正在答题嘛，别乱点'
    if (status == 'EXAM_WEEK') or (status == 'EXAM_REAL'):
        cache.set_tag(message.source, 'jump_to_EXAM_DAY_ensure')
        return u'确定要放弃现在正在进行的答题？\n确定回复Y，取消回复N'
    return u'你点击了每日评测菜单'


@robot.filter('help')
def user_help():
    return u'点击相应的按钮开始答题，系统会自动记录你的分数'


robot.run(host='0.0.0.0',port=80)